package com.zy.drug.controller;

import com.zy.drug.pojo.LoginParam;
import com.zy.drug.pojo.User;
import com.zy.drug.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("listAllUser")
    @ResponseBody
    public List<User> listAllUser(){
        return userService.listAllUser();
    }
    @PostMapping("login")
    public Map<String,Object> login(@RequestBody LoginParam param){
        Map<String,Object> res = new HashMap<>();
        if (param.getUsername()!= null && param.getPassword() != null){
            res.put("code",200);
            res.put("msg","登录成功");
            res.put("username",param.getUsername());
            res.put("token","123456");
            return res;
        }
        else {
            res.put("code",201);
            res.put("msg","登录失败");
            return res;
        }
    }
}
